#include "SMPPMessageSubmissionResponseTLVs.hpp"

using namespace smpp::pdu;

MessageSubmissionResponseTLVs::MessageSubmissionResponseTLVs(
const AdditionalStatusInfoText *nAdditionalStatusInfoText,
const DeliveryFailureReason *nDeliveryFailureReason,
const DpfResult *nDpfResult,
const NetworkErrorCode *nNetworkErrorCode,
const CongestionState *nCongestionState):
_AdditionalStatusInfoText(0),
_DeliveryFailureReason(0),
_DpfResult(0),
_NetworkErrorCode(0),
_CongestionState(0){
	if(_AdditionalStatusInfoText)
		_AdditionalStatusInfoText = 
		new AdditionalStatusInfoText(*nAdditionalStatusInfoText);
	if(_DeliveryFailureReason)
		_DeliveryFailureReason = new DeliveryFailureReason(
		*nDeliveryFailureReason);
	if(_DpfResult)
		_DpfResult = new DpfResult(*nDpfResult);
	if(_NetworkErrorCode)
		_NetworkErrorCode = new NetworkErrorCode(*nNetworkErrorCode);
	if(_CongestionState)
		_CongestionState = new CongestionState(*nCongestionState);
}

MessageSubmissionResponseTLVs::MessageSubmissionResponseTLVs(
const MessageSubmissionResponseTLVs &nMessageSubmissionResponseTLVs):		
_AdditionalStatusInfoText(0),
_DeliveryFailureReason(0),
_DpfResult(0),
_NetworkErrorCode(0),
_CongestionState(0){
	if(nMessageSubmissionResponseTLVs.getAdditionalStatusInfoText())
		_AdditionalStatusInfoText = 
		new AdditionalStatusInfoText(
		*nMessageSubmissionResponseTLVs.getAdditionalStatusInfoText());
	if(nMessageSubmissionResponseTLVs.getDeliveryFailureReason())
		_DeliveryFailureReason = new DeliveryFailureReason(
		*nMessageSubmissionResponseTLVs.getDeliveryFailureReason());
	if(nMessageSubmissionResponseTLVs.getDpfResult())
		_DpfResult = new DpfResult(
		*nMessageSubmissionResponseTLVs.getDpfResult());
	if(nMessageSubmissionResponseTLVs.getNetworkErrorCode())
		_NetworkErrorCode = new NetworkErrorCode(
		*nMessageSubmissionResponseTLVs.getNetworkErrorCode());
	if(nMessageSubmissionResponseTLVs.getCongestionState())
		_CongestionState = new CongestionState(
		*nMessageSubmissionResponseTLVs.getCongestionState());
}

MessageSubmissionResponseTLVs::~MessageSubmissionResponseTLVs(){
	if(_AdditionalStatusInfoText)
		delete _AdditionalStatusInfoText;
	if(_DeliveryFailureReason)
		delete _DeliveryFailureReason;
	if(_DpfResult)
		delete _DpfResult;
	if(_NetworkErrorCode)
		delete _NetworkErrorCode;
	if(_CongestionState)
		delete _CongestionState;
}

void MessageSubmissionResponseTLVs::setAdditionalStatusInfoText(
	const AdditionalStatusInfoText *nAdditionalStatusInfoText){
	if(_AdditionalStatusInfoText){
		delete _AdditionalStatusInfoText;
		_AdditionalStatusInfoText = 0;
	}
	if(nAdditionalStatusInfoText)
		_AdditionalStatusInfoText = 
		new AdditionalStatusInfoText(*nAdditionalStatusInfoText);
}

const AdditionalStatusInfoText *
	MessageSubmissionResponseTLVs::getAdditionalStatusInfoText() const{
	return _AdditionalStatusInfoText;
}

void MessageSubmissionResponseTLVs::setDeliveryFailureReason(
	const DeliveryFailureReason *nDeliveryFailureReason){
	if(_DeliveryFailureReason){
		delete _DeliveryFailureReason;
		_DeliveryFailureReason = 0;
	}
	if(nDeliveryFailureReason)
		_DeliveryFailureReason = 
		new DeliveryFailureReason(*nDeliveryFailureReason);
}

const DeliveryFailureReason *
	MessageSubmissionResponseTLVs::getDeliveryFailureReason() const{
	return _DeliveryFailureReason;
}

void MessageSubmissionResponseTLVs::setDpfResult(
	const DpfResult *nDpfResult){
	if(_DpfResult){
		delete _DpfResult;
		_DpfResult = 0;
	}
	if(nDpfResult)
		_DpfResult = new DpfResult(*nDpfResult);
}

const DpfResult *MessageSubmissionResponseTLVs::getDpfResult() const{
	return _DpfResult;
}

void MessageSubmissionResponseTLVs::setNetworkErrorCode(
	const NetworkErrorCode *nNetworkErrorCode){
	if(_NetworkErrorCode){
		delete _NetworkErrorCode;
		_NetworkErrorCode = 0;
	}
	if(nNetworkErrorCode)
		_NetworkErrorCode = new NetworkErrorCode(*nNetworkErrorCode);
}

const NetworkErrorCode *
	MessageSubmissionResponseTLVs::getNetworkErrorCode() const{
	return _NetworkErrorCode;
}	

void MessageSubmissionResponseTLVs::setCongestionState(
	const CongestionState *nCongestionState){
	if(_CongestionState){
		delete _CongestionState;
		_CongestionState = 0;
	}
	if(nCongestionState)
		_CongestionState = new CongestionState(*nCongestionState);
}

const CongestionState *
	MessageSubmissionResponseTLVs::getCongestionState() const{
	return _CongestionState;
}	

const quint16 MessageSubmissionResponseTLVs::getLength() const{
	quint16 length(0);
	if(_AdditionalStatusInfoText)
		length += 4 + _AdditionalStatusInfoText->getLength();
	if(_DeliveryFailureReason)
		length += 4 + _DeliveryFailureReason->getLength();
	if(_DpfResult)
		length += 4 + _DpfResult->getLength();
	if(_NetworkErrorCode)
		length += 4 + _NetworkErrorCode->getLength();
	return length;
}
